package com.zhao.modleclass.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhao.modleclass.Helper.RecyclerViewAdapterHelper;
import com.zhao.modleclass.R;
import com.zhao.modleclass.activity.SC_TeacherRActivity;
import com.zhao.modleclass.bean.SearchClassBiaoQianBean;

import java.util.List;

/**
 * Created by 张昭 on 2016/11/28.
 */

public class BiaoQianAdapter extends RecyclerViewAdapterHelper{
    private Context mContext;
    private List<SearchClassBiaoQianBean.DataBean> mList;
    private RecyclerView recyclerView;
    public BiaoQianAdapter(Context context, List list,RecyclerView recyclerView) {
        super(context, list);
        this.mContext=context;
        this.mList=list;
        this.recyclerView=recyclerView;
    }



    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view=mInflater.inflate(R.layout.fragment_searchclass_item_gengduobiaoqian,parent,false);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position=recyclerView.getChildLayoutPosition(v);
                int tagID=mList.get(position).getTagId();
                String name=mList.get(position).getTagName();
                Intent intent=new Intent(mContext, SC_TeacherRActivity.class);
                intent.putExtra("tagRID",tagID);
                intent.putExtra("TitleName",name);
                mContext.startActivity(intent);
            }
        });
        return new MyHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder){
            Glide.with(mContext).load(mList.get(position).getTagImageUrl()).into(((MyHolder) holder).imageView_search);
            ((MyHolder) holder).textView_search.setText("#"+mList.get(position).getTagName());
        }
    }
    class MyHolder extends RecyclerView.ViewHolder {
        private ImageView imageView_search;
        private TextView textView_search;
        public MyHolder(View itemView) {
            super(itemView);
            imageView_search= (ImageView) itemView.findViewById(R.id.fragment_searchclass_img);
            textView_search= (TextView) itemView.findViewById(R.id.fragment_searchclass_title);
        }
    }

    @Override
    public void reloadRecyclerView(List _list, boolean isClear) {
        if (isClear) {
            mList.clear();
        }
        mList.addAll(_list);
        notifyDataSetChanged();
    }
}
